01 Exploring KITTI

len(ds.get_split("train"))
3712
from collections import defaultdict
counts = defaultdict(int)

for label in (KITTI_ROOT/"training"/"label_2").glob("*"):
    num     = label.stem
    calib   = ds.read_calib(KITTI_ROOT/"training"/"calib"/(num+".txt"))
    label:List[o3d._ml3d.datasets.kitti.Object3d] = ds.read_label(label, calib)
    for box in label:
        counts[box.label_class] += 1
counts
defaultdict(int,
            {'Car': 28742,
             'DontCare': 13873,
             'Van': 2914,
             'Pedestrian': 4487,
             'Cyclist': 1627,
             'Person_sitting': 222})

source

loadVeloAsPcd

 loadVeloAsPcd (fname:Union[str,os.PathLike])
num:str = "000000"
fname   = KITTI_ROOT/"training"/"velodyne_reduced"/(num+".bin")
cloud   = loadVeloAsPcd(fname)
cloud
PointCloud on CPU:0 [20285 points (Float32)].
Attributes: color_gradients (dtype = Float32, shape = {20285, 3}), colors (dtype = Float32, shape = {20285, 3}), normals (dtype = Float32, shape = {20285, 3}), intensities (dtype = Float32, shape = {20285}).

source

plotCloud

 plotCloud (cloud:open3d.cpu.pybind.t.geometry.PointCloud,
            boxes:Iterable[open3d._ml3d.datasets.kitti.Object3d]=[])
fig = plotCloud(cloud)
fig.show()
image = KITTI_ROOT/"training"/"image_2"/(num+".png")
with Image.open(image) as png:
    png.show()

calib = ds.read_calib(KITTI_ROOT/"training"/"calib"/(num+".txt"))
calib
{'world_cam': array([[-0.0015961 , -0.00527065,  0.9999848 ,  0.        ],
        [-0.99991626,  0.0128487 , -0.00152827,  0.        ],
        [-0.01284044, -0.99990356, -0.00529071,  0.        ],
        [-0.02236671, -0.05967891, -0.332549  ,  1.        ]],
       dtype=float32),
 'cam_img': array([[ 7.070493e+02,  0.000000e+00,  0.000000e+00,  0.000000e+00],
        [ 0.000000e+00,  7.070493e+02,  0.000000e+00,  0.000000e+00],
        [ 6.040814e+02,  1.805066e+02,  1.000000e+00,  1.000000e+00],
        [ 4.575831e+01, -3.454157e-01,  4.981016e-03,  0.000000e+00]],
       dtype=float32)}
# TODO: Project this correctly in to the 3D plot
label = KITTI_ROOT/"training"/"label_2"/(num+".txt")
label:List[o3d._ml3d.datasets.kitti.Object3d] = ds.read_label(label, calib)
label[0].generate_corners3d()
array([[-4.9337853 ,  1.84000001, 79.32568998],
       [-3.20378585,  1.84000001, 79.32431234],
       [-3.20621464,  1.84000001, 76.27431331],
       [-4.93621409,  1.84000001, 76.27569095],
       [-4.9337853 ,  0.18000001, 79.32568998],
       [-3.20378585,  0.18000001, 79.32431234],
       [-3.20621464,  0.18000001, 76.27431331],
       [-4.93621409,  0.18000001, 76.27569095]])
counts
defaultdict(int,
            {'Car': 28742,
             'DontCare': 13873,
             'Van': 2914,
             'Pedestrian': 4487,
             'Cyclist': 1627,
             'Person_sitting': 222})